home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-02-16 | 3.1 KB | 77 lines | [TEXT/GEOL] |
- Item 7851557 15-Feb-90 10:13PST
-
- From: MADA2 MacApp Dev Assoc, Curtis Faith,IVC
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: TTEView Question (Compuserve)
-
- From the Compuserve forums comes this question about some of the internals of
- TTEView. I have not personally spent enough time inside TTEViews to be able to
- answer this question intelligently.
-
- Anyone have any comments?
-
- ____________________
- From: John MacVeigh 72467,2141
-
- While trying to debug a problem with a TTEView object I have run into what I
- think is a flaw with the use of the fSavedTEHandle field and the fFreeText
- field. The flaw only surfaces when TTEView.StuffText is called more than once.
- Here is my thinking:
-
- The purpose of fSavedTEHandle appears to be to provide a valid handle for the
- fHTE^^.hText field when fHTE is passed to TEDispose (see TTEView.Free).
- Apparently the idea is to hold on to the handle which is originally assigned to
- hText by the TENew call. This handle is placed back into the fHTE record just
- before TEDispose is called. This allows the fText field to be freed separately.
-
- So far, so good. Now let's look at fFreeText. This Boolean controls whether the
- fText field is actually disposed when TTEView.Free is called. An alternate name
- for this field could be fTEOwnsText. That is, if the TTEView object owns the
- text, then it may dispose of it at will. Otherwise someone else is responsible
- for it, indeed, may care very much about it.
-
- Now, finally, look at TTEView.StuffText. If the text to be stuffed (theText) is
- different each time that StuffText is called, the routine will end up throwing
- away fSavedTEHandle and saving the old hText field before stuffing the new
- text.
-
- The result is that, during multiple calls to StuffText, fSavedTEHandle becomes
- a cache of previous text handles, rather than a holder for the original hText
- field. It does not check the setting of fFreeText, and thus can violate the
- rule that someone else is responsible for freeing the fText field.
-
- IF fSavedTEHandle <> theText THEN
- BEGIN
- DisposIfHandle(fSavedTEHandle); { ...we have no choice but to dispose it }
- fSavedTEHandle := fHTE^^.hText; { Save existing handle }
- END;
-
- (I do not agree with the comment about no choice) should be replaced with:
-
- If fFreeText & (theText <> fHTE^^.hText) Then
- DisposIfHandle (fHTE^^.hText);
-
- Essentially this says that if we are stuffing a new handle, just forget about
- the previous one (though if we own it [fFreeText = True] then we kill it off,
- as well). The rest of the routine remains unchanged.
-
- In addition, TTEView.Free needs to check that fText and fSavedTEHandle are not
- the same handle, so that the hText field is not disposed twice. Umm, I'll leave
- this as an exercise for the reader.
-
- I think these changes enforce the setting of fFreeText without failing when
- someone tries to be (overly) clever and repeatedly stuffs fHTE^^.hText back
- into the TTEView.
-
- Have I missed anything here?
-
- --John MacVeigh
- _________________
- Send replies to me at MADA2 and I will forward them to John.
-
- - Curtis
-
-
-